package component.firstPage.Login;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import util.ConnectionUtils;


public class _Login {
    public static String login(String userAccount, String userPassword) {
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        Connection connection = null;
        try {
            connection = ConnectionUtils.getConn();
            String sql = "select id from user where account = ? and password = ?";
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, userAccount);
            preparedStatement.setString(2, userPassword);
            resultSet = preparedStatement.executeQuery();

            if (resultSet.next()) {
                return resultSet.getString("id");
            }
        } catch (SQLException e) {
            System.err.println("登录验证时数据库操作出现异常: " + e.getMessage());
        } finally {
            ConnectionUtils.close(connection, preparedStatement, resultSet);
        }
        return null;
    }
}
